<?php
namespace PsiFramework\Plugins\Form\Classes;

use PsiFramework\Plugins\Form\Classes\Model\FieldType;

use PsiFramework\Plugins\Form\Classes\DAO\FieldTypeDAO;

use PsiFramework\Plugins\Form\Classes\Model\Form;

use PsiFramework\Plugins\Form\Classes\DAO\FormDAO;

use PsiFramework\Classes\Factory\DAOFactory;

use PsiFramework\Classes\Util\Parameters\PluginConfig;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The FormPluginConfig class is the class to manage how plugin work
 *
 * @package Classes
 */
class FormPluginConfig extends PluginConfig
{
    
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 
     * @see \PsiFramework\Classes\Util\Parameters\PluginConfig::retrieveObjectParameter()
     */
    public function retrieveObjectParameter(/*string*/ $objectName)
    {
        parent::retrieveObjectParameter($objectName);
        
        $this->_logger->debug('Retrieve parameters '.$objectName.' from database.');
        
        /* @var $formDao FormDAO */
        $formDao = DAOFactory::getDAO('Form');
        $form = $formDao->retrieveByResponseName($objectName);
        
        /* @var $form Form */
        if (!is_null($form)) {
            return $form->getResponseParameters();
        } else {
            
            /* @var $fieldTypeDao FieldTypeDAO */ 
            $fieldTypeDao = DAOFactory::getDAO("FieldType");
            $fieldType = $fieldTypeDao->retrieveByResponseName($objectName);
            
            /* @var $fieldType FieldType */
            if (!is_null($fieldType)) {
                return $fieldType->getResponseParameters();
            } else {
                return null;
            }
        }
    }
    
}